package com.project.system.service.impl;

import com.project.common.annotation.DataScope;
import com.project.common.utils.DateUtils;
import com.project.system.domain.SysAttendance;
import com.project.system.mapper.SysAttendanceMapper;
import com.project.system.mapper.SysDeptMapper;
import com.project.system.mapper.SysUserMapper;
import com.project.system.service.ISysAttendanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考勤记录信息Service业务层处理
 *
 * @author kang
 * @date 2021-03-17
 */
@Service
public class SysAttendanceServiceImpl implements ISysAttendanceService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private SysDeptMapper sysDeptMapper;

    @Resource
    private SysAttendanceMapper sysAttendanceMapper;

    /**
     * 查询考勤记录信息
     *
     * @param attendanceId 考勤记录信息ID
     * @return 考勤记录信息
     */
    @Override
    public SysAttendance selectSysAttendanceById(Long attendanceId) {
        return sysAttendanceMapper.selectSysAttendanceById(attendanceId);
    }

    /**
     * 查询考勤记录信息列表
     *
     * @param sysAttendance 考勤记录信息
     * @return 考勤记录信息
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<SysAttendance> selectSysAttendanceList(SysAttendance sysAttendance) {
        return sysAttendanceMapper.selectSysAttendanceList(sysAttendance);
    }

    /**
     * 新增考勤记录信息
     *
     * @param sysAttendance 考勤记录信息
     * @return 结果
     */
    @Override
    public int insertSysAttendance(SysAttendance sysAttendance) {
        sysAttendance.setClockTime(DateUtils.getNowDate());
        sysAttendance.setCreateTime(DateUtils.getNowDate());
        return sysAttendanceMapper.insertSysAttendance(sysAttendance);
    }

    /**
     * 修改考勤记录信息
     *
     * @param sysAttendance 考勤记录信息
     * @return 结果
     */
    @Override
    public int updateSysAttendance(SysAttendance sysAttendance) {
        sysAttendance.setUpdateTime(DateUtils.getNowDate());
        return sysAttendanceMapper.updateSysAttendance(sysAttendance);
    }

    /**
     * 批量删除考勤记录信息
     *
     * @param attendanceIds 需要删除的考勤记录信息ID
     * @return 结果
     */
    @Override
    public int deleteSysAttendanceByIds(Long[] attendanceIds) {
        return sysAttendanceMapper.deleteSysAttendanceByIds(attendanceIds);
    }

    /**
     * 删除考勤记录信息信息
     *
     * @param attendanceId 考勤记录信息ID
     * @return 结果
     */
    @Override
    public int deleteSysAttendanceById(Long attendanceId) {
        return sysAttendanceMapper.deleteSysAttendanceById(attendanceId);
    }
}
